-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable expansion outside queries #941
Conversation
edf2efc
to
854138d
Compare
I haven't added histogram specific arguments like |
@neelasha23 I think expanding the parameters when we read the arguments string would be better so we automatically add expansion to them. Otherwise, we'll have to remember to add this feature to every argument we add. If you look at the SQL magic implementation, there should be a part where we obtain the raw argument string e.g. |
Addressed the comment. Please review @edublancas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the variable expansion works well, but I have some questions. Of course the intention is to use variables to specify argument values like this:
%%sql --save {{foo}} --no-execute
SELECT 1
But in testing I found that you can also use them to specify the argument flags themselves, like this:
arg = "--save"
%%sql {{arg}} snippet --no-execute
SELECT 1
This works fine when the arguments are specified correctly. However, I could do something like
arg = "--not_an_arg"
and the statement will still run without throwing an error:
@edublancas @neelasha23 Do we want to allow users to specify argument flags using variables in this way? I assume this wasn't the original intent. It could definitely be helpful but might also open up more issues in the future.
If so, I think we will need to call expand_args()
before we parse/check for invalid arguments. We will also need to include this in the documentation and spend more time thinking about potential corner cases/bugs.
I think for this PR we should only handle arguments and not flags. I have changed the approach. Previously I had tried a couple of approaches:
Here are the changes: columns Regarding the error, now it will display error if we try to use the snippet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neelasha23 Manual testing checks out. Overall your last solution was more streamlined but I can see why you needed to revert back to this approach in order to disallow parametrizing flags. I'll leave it up to @edublancas if he feels like this is too clunky. If we were to add a new command it would have to remember to include this logic:
args = parser.parse_args(others)
if is_rendering_required(" ".join(others)):
expand_args(args, user_ns)
Not sure if we even plan on adding new commands anytime soon though.
It would be helpful to add a warning to users when they try to parametrize a flag. Even though the flag isn't registered, currently the command still executes so users may be confused why it isn't working. So if the user tried this:
arg = "--save"
%%sql {{arg}} snippet
SELECT 1
They should receive UserWarning: Parametrization of argument flags is not allowed
or something like that.
I'm confused. this approach sounds like a much more robust alternative than adding code to each of the SQL commands, and you mentioned "I have reverted to this approach", but then I looked at the code and there are a few snippets that look like this: if is_rendering_required(" ".join(others)):
expand_args(args, user_ns) the objective is to have a single place for expanding the |
What i understood from your previous comment, you mentioned that we we might forget to add every-time we add a new Now if we add any new command like
If we work directly on the string we need to add multiple rules/ regex patterns to ensure we pick up only the arguments and I'm not very sure of this approach. Let me know what you think. If you have any suggestions it would be helpful |
@neelasha23 oh, you're right. I thought we could add a single piece of logic that would work for all commands ( just fix the conflicts, the integration tests and this should be good to go! |
2cb3840
to
9fa7544
Compare
author Eduardo Blancas <github@blancas.io> 1706144090 -0600 committer neelasha23 <neelasha.sen@gmail.com> 1706161587 +0530 parent aaf4021 author Eduardo Blancas <github@blancas.io> 1706144090 -0600 committer neelasha23 <neelasha.sen@gmail.com> 1706161586 +0530 parent aaf4021 author Eduardo Blancas <github@blancas.io> 1706144090 -0600 committer neelasha23 <neelasha.sen@gmail.com> 1706161584 +0530 parent aaf4021 author Eduardo Blancas <github@blancas.io> 1706144090 -0600 committer neelasha23 <neelasha.sen@gmail.com> 1706161581 +0530 Update README.md arg expansion guide docstring modified doc fix minor fix supported args table orient Parse line new util func rendering string fix test Removed table with doc fix magic_sql removed comment removed comment docstring Lint revert removals fix add no_var explorer guide profile testing docs tables doc tables doc tests schema snippets docs snippets
conflicts and tests are fixed now @edublancas |
Describe your changes
Added variable expansion support for the string type arguments in the following:
%sqlcmd columns
%sqlcmd explore
%sqlcmd profile
%sqlcmd snippets
%sqlcmd tables
%sqlcmd test
%sql
%sqlplot
Integer/ float arguments of histogram plot like
bins
,binwidth
, etc are not supported.Issue number
Closes #699
Checklist before requesting a review
pkgmt format
📚 Documentation preview 📚: https://jupysql--941.org.readthedocs.build/en/941/